const userCtrl = require("./controller/userCtrl");
const rlCtrl = require("./controller/rlCtrl");
const workCtrl = require("./controller/workCtrl");
const messageCtrl = require("./controller/messageCtrl");
const fileGiteeCtrl = require("./controller/fileGitee")
const appCtrl = require("./controller/application")
const wx135Ctrl = require("./controller/wechat/135")
const HHAICtrl = require("./controller/AI/hh")

const tool = require("./tool.js")

let routeConfigs = {
    user: {
        ctrl: userCtrl,
        router: [{
            url: 'user/register',
            method: "GET"
        }, {
            url: 'user/getUserInfo',
            method: "GET"
        }, {
            url: 'user/getDepartmentPerson',
            method: "GET"
        }],

    },
    rl: {
        ctrl: rlCtrl,
        router: [{
            url: 'rl/getRl',
            method: "GET"
        }]
    },
    file: {
        ctrl: fileGiteeCtrl,
        router: [{
            url: 'file/upload',
            method: "POST"
        }]
    },
    app: {
        ctrl: appCtrl,
        router: [{
            url: 'app/appConfig',
            method: "GET"
        }, {
            url: 'app/appMain',
            method: "GET"
        }]
    },
    wx: {
        ctrl: wx135Ctrl,
        router: [{
            url: 'wx/135/getList',
            method: "GET"
        }]
    },
    AI: {
        ctrl: HHAICtrl,
        router: [{
            url: 'AI/HH/HH',
            authority: "0000010000",
            method: "GET"
        }]
    },
    message: {
        ctrl: messageCtrl,
        router: [{
            url: 'message/getMyMessage',
            method: "GET"
        }, {
            url: 'message/getQ',
            method: "GET"
        }, {
            url: 'message/getNews',
            method: "GET"
        }, {
            url: 'message/setWrite',
            method: "GET"
        }, {
            url: 'message/upQ',
            method: "POST"
        }, {
            url: 'message/upNews',
            method: "POST"
        }, {
            url: 'message/getCanUp',
            method: "GET"
        }, {
            url: 'message/setQImg',
            method: "POST"
        }, {
            url: 'message/create',
            method: "GET"
        }, {
            url: 'message/face',
            method: "GET"
        }, {
            url: 'message/psd',
            method: "GET"
        }]
    },
    work: {
        ctrl: workCtrl,
        router: [{
            url: 'work/add',
            method: "GET"
        }, {
            url: 'work/save',
            method: "GET"
        }, {
            url: 'work/getPaper',
            method: "GET"
        }, {
            url: 'work/setCanSee',
            method: "GET"
        }, {
            url: 'work/getMyWork',
            method: "GET"
        }, {
            url: 'work/delMyWork',
            method: "GET"
        }, {
            url: 'work/getMyDoWork',
            method: "GET"
        }]
    }
}

class router {
    constructor(app) {
        this.app = app
    }
    addRoute(routeConfigs) {
        let AAC = {}  // Account authority controller
        Object.keys(routeConfigs).map((rKey) => {
            for (let rc of routeConfigs[rKey].router) {
                AAC[rc.url] = rc
                if (rc.method == "GET") {
                    this.app.get("/" + rc.url, (req, resp) => {
                        req.query.uId=tool.decodeToken(req.query.uToken) 
                        console.log(9)
                        return routeConfigs[rKey].ctrl[rc.url.split("/").slice(-1)].call(this, req, resp)
                    })
                }
            }
        })
        return AAC
    }
}

module.exports = {
    router, routeConfigs
}